package com.tb.ClassSchedule;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.net.sip.SipAudioCall;
import android.os.Build;
import android.text.Layout;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.larswerkman.holocolorpicker.ColorPicker;
import com.larswerkman.holocolorpicker.OpacityBar;
import com.larswerkman.holocolorpicker.SaturationBar;
import com.larswerkman.holocolorpicker.ValueBar;

/**
 * Created by guich on 2016/8/13.
 */
public class TitleView extends FrameLayout{

    private ImageButton    backButton;
    private ImageButton    okButton;
    private TextView       title;
    private RelativeLayout bg;


    public TitleView(Context context, AttributeSet attrs) {
        super(context, attrs);
        LayoutInflater.from(context).inflate(R.layout.title,this);
        backButton = (ImageButton) findViewById(R.id.title_back_button);
        okButton = (ImageButton) findViewById(R.id.title_ok_button);
        title = (TextView) findViewById(R.id.activity_title);
        bg = (RelativeLayout) findViewById(R.id.title_bg);
        backButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                ((Activity)getContext()).finish();
            }
        });

        int color;
        if(isInEditMode()){
            color = 0;
        }else{
            color = MainActivity.sharedPreferences.getInt("color",0);
        }

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            bg.setPadding(0,MainActivity.statusBarHeight,0,0);
        }
        bg.setBackgroundColor(color);

    }



    public void setTitle(String title){
        this.title.setText(title);
    }

    public void setOkButtonListener(OnClickListener listener){
        okButton.setVisibility(VISIBLE);
        okButton.setOnClickListener(listener);
    }

    public void changeOkImage(Bitmap bitmap){
        okButton.setImageBitmap(bitmap);
    }

}
